import {_decorator, Node, Prefab, instantiate} from 'cc';
import {SceneManager} from 'db://assets/Scripts/Scene/SceneManager';
import DataManager from "db://assets/Scripts/Runtime/DataManager";
import {ItemStatusEnum, ItemTypeEnum, SceneEnum} from "db://assets/Scripts/Enum";

const {ccclass, property} = _decorator;


@ccclass('H2SceneManager')
export class H2SceneManager extends SceneManager {

    @property(Prefab)
    keyPrefab: Prefab = null

    @property(Node)
    keyPlaceholder: Node = null // 这个节点用来预定钥匙在场景中的位置，方便直接定位

    type: SceneEnum = SceneEnum.H2

    render() {
        super.render()
        this.items.destroyAllChildren()

        const key = DataManager.Instance.items.find(i => i.type === ItemTypeEnum.Key)
        if (key && key.status === ItemStatusEnum.Scene) { // 如果钥匙的状态是在场景中，就渲染到 keyPlaceholder 的位置上
            const keyNode = instantiate(this.keyPrefab)
            this.items.addChild(keyNode)
            keyNode.setPosition(this.keyPlaceholder.position)
        }
    }
}

